/*
 * This file is part of Sparwe.
 *
 *  Sparwe is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Sparwe is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Sparwe.  If not, see <http://www.gnu.org/licenses/>.
 */ 

#include <iostream>
#include "exceptions.h"

using namespace sp_core;

Exception::Exception() : mMessage("standard exception.")
{

}

Exception::Exception(std::string message) : mMessage(message)
{

}

Exception::~Exception() throw()
{

}

const char* Exception::what()
{
	return mMessage.c_str();
}

const char* Exception::What()
{
	return what();
}

std::vector<std::string> Exception::Backtrace()
{
	const size_t maxDepth = 128;
	size_t stackDepth;
	void *stackAddresses[maxDepth];
	char **stackStrings;

	stackDepth = backtrace(stackAddresses, maxDepth);
	stackStrings = backtrace_symbols(stackAddresses, stackDepth);

	std::vector<std::string> trace;
	for (size_t i = 1; i < stackDepth; ++i)
	{
		trace.push_back(std::string(stackStrings[i]));
	}
				
	delete stackStrings;
	return trace;
}


